var ZYRequestClient = require("../../../../utils/zy-request");
var requestClient;
const app = getApp();
Page({
  data:{
    sealId:0,
    sealInfo:{},
    approvalList:[],
    editable:'false',
    navbarData:{
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '印章信息', //导航栏 中间的标题
      white:true
     },
     // 导航头的高度
     height: app.globalData.height * 2 + 20
  },
  onLoad(options) {
    var _this = this;
    requestClient = new ZYRequestClient();
    _this.setData({
      sealId:options.id,
      editable:options.editable
    });
    requestClient.getSealInfo(options.id,function(res){
        _this.setData({
          sealInfo:res.data.data
        });
    });
  },
  onShow(){
    this.loadApprovalList();
  },
  // 加载审批流程
  loadApprovalList(){
    var _this = this;
    requestClient.getApprovalProcessListBySealId(_this.data.sealId,function(res){
        _this.setData({
          approvalList:res.data.data
        });
    });
  },
  // 盖章前确认用印人
  bindFaceChange(e){
    var _this = this;
    requestClient.checkFunctionPermission(1007,'您没有权限编辑印章，请联系企业创建者！',function(){
      // 更新
      requestClient.updateSealFacePhoto(_this.data.sealId,
        e.detail.value,function(res){
          if(res.data.data){
            _this.setData({
              'sealInfo.facePhoto':e.detail.value
            });
          }
      })
    },function(){
      _this.setData({
        'sealInfo.facePhoto':!e.detail.value
      });
    });
  },
  // 盖章时自动拍照
  bindChange(e){
    var _this = this;
    requestClient.checkFunctionPermission(1007,'您没有权限编辑印章，请联系企业创建者！',function(){
      // 更新
      requestClient.updateSealForcePhotograph(_this.data.sealId,
        e.detail.value,function(res){
          if(res.data.data){
            _this.setData({
              'sealInfo.forcePhotograph':e.detail.value
            });
          }
      })
    },function(){
      _this.setData({
        'sealInfo.forcePhotograph':!e.detail.value
      });
    });
  },
  copywxtap() {
    wx.setClipboardData({
      data: this.data.sealInfo.mac,
      success (res) {
        wx.getClipboardData({
          success (res) {
            wx.showToast({
              title: '复制成功',
            })
          }
        })
      }
    })
  },
})